package com.linkcard.commen.tools;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSession;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.linkcard.list.manager.LinksManager;
import com.linkcard.list.model.Links;
import com.linkcard.user.manager.WebsiteConfigerManager;
import com.linkcard.user.model.WebsiteConfiger;

public class ConfigListener implements ServletContextListener,
		ServletContextAttributeListener {
	private ServletContext application = null ; 
	  
	private HttpSession session = null ;
	public void contextDestroyed(ServletContextEvent sce) {

	}

	public void contextInitialized(ServletContextEvent sce) {
		 ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
			this.application=sce.getServletContext() ; 
			WebsiteConfigerManager websiteManager=(WebsiteConfigerManager)context.getBean("websiteConfigerManager");
			List list=websiteManager.websiteColumnList(null);
			String path = application.getRealPath("/WEB-INF/classes/websiteconfig.xml");
			WebsiteConfiger website=websiteManager.websiteConfig(path);
			//链接
			LinksManager linksManager=(LinksManager)context.getBean("linksManager");
			List links=linksManager.linksListForRecommend();
			
			this.application.setAttribute("columns", list);
			this.application.setAttribute("website", website);
			this.application.setAttribute("links", links);
	}

	public void attributeAdded(ServletContextAttributeEvent scab) {

	}

	public void attributeRemoved(ServletContextAttributeEvent scab) {

	}

	public void attributeReplaced(ServletContextAttributeEvent scab) {

	}

}
